// Copyright 2012 Sergio, Raul, Dorival. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#ifndef GEMLAB_DRAW_H
#define GEMLAB_DRAW_H

// Std Lib
#include <iostream>

namespace GemLab {

inline void MPLHeader (std::ostream & os)
{
    // header
    os << "from numpy import array, sqrt\n";
    os << "from pylab import figure, text, show, axis, plot, grid, savefig\n";
    os << "from pylab import matplotlib as MPL\n\n";
    os << "PH = MPL.path.Path\n";
    os << "PP = MPL.patches\n";
    os << "PC = MPL.patches.PathPatch\n\n";

    // colors
    os << "# colors\n";
    os << "pink    = (250/255.0,204/255.0,228/255.0)\n";
    os << "dred    = (163/255.0,  0/255.0,  0/255.0)\n";
    os << "lblue   = (217/255.0,228/255.0,255/255.0)\n";
    os << "lgreen  = (100/255.0,241/255.0,193/255.0)\n";
    os << "dblue   = ( 45/255.0,  0/255.0,160/255.0)\n";
    os << "orange  = (241/255.0,125/255.0,  0/255.0)\n";
    os << "dpink   = (170/255.0, 94/255.0,137/255.0)\n";
    os << "lyellow = (234/255.0,228/255.0,179/255.0)\n\n";

    // figure, axis, and data
    os << "# figure, axis, and data\n";
    os << "fig = figure()\n";
    os << "ax  = fig.add_subplot(111)\n";
    os << "dat = []\n\n";
}

inline void MPLAddPatch (std::ostream & os, char const * EdgeColor="dblue", char const * FaceColor="lblue")
{
    os << "if len(dat)>0:\n";
    os << "    cmd,vert = zip(*dat)\n";
    os << "    ph       = PH (vert, cmd)\n";
    os << "    pc       = PC (ph, edgecolor=" << EdgeColor << ", facecolor=" << FaceColor << ", linewidth=2)\n";
    os << "    ax.add_patch  (pc)\n\n";
}

inline void MPLShow (std::ostream & os)
{
    os << "grid()\n";
    os << "axis('scaled')\n";
    os << "show()\n";
}

inline void MPLSaveFig (char const * FileKey, std::ostream & os)
{
    String fn(FileKey);
    fn.append(".png");
    os << "grid()\n";
    os << "axis('scaled')\n";
    os << "savefig('"<< fn << "')\n";
}

}; // namespace GemLab

#endif // GEMLAB_DRAW_H
